package java51.homew0614;

// 读取一个文件夹中多个文件
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class SendThread extends Thread {
	Socket s;

	public SendThread(Socket s) {
		super();
		this.s = s;
	}

	public void run() {
		File file = new File("D:\\1122");
		File fr[] = file.listFiles();
		for (File f : fr) {
			while (true) {
				try {
					FileInputStream is = new FileInputStream(f);
					OutputStream out = s.getOutputStream();
					String name = f.getName();
					byte b1[] = name.getBytes();
					out.write(b1.length);
					out.write(b1);
					byte b2[] = new byte[1024];
					int len = 0;
					while ((len = is.read(b2)) > -1) {
						out.write(b2, 0, len);
						out.flush();
					}
					// String s1 = "一个文件读取完";
					// byte b3[] = s1.getBytes();
					// out.write(b3.length);
					// out.write(b3);
					is.close();
					out.close();

					break;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			try {
				OutputStream out = s.getOutputStream();
				String s1 = "所有文件读取完";

			} catch (IOException e) {

				e.printStackTrace();
			}

		}
	}
}
